<?php
namespace app\plus_exam\model;
use think\Model;
/**
 * 考场管理
 * Class School
 * @package app\exam\model
 */
class School extends Model{

    protected $pk       = 'id';
    protected $table    = 'sp_plus_exam_school';
    protected $autoWriteTimestamp = true;
    protected $pageNumber = 20;

    /**
     * 单个
     * @param int $param
     * @return array
     */
    public function find_info($param) {
        return self::get($param);
    }

    /**
     * 列表
     * @access public
     * @param array $where
     */
    public function select_lists(){
        return $this->order('id','desc')->paginate($this->pageNumber);
    }

    /**
     * 添加
     * @param array $param
     * @return int
     */
    public function add_data($param) {
        $data = [
            'category'        => $param['category'],
            'category_id'     => $param['category_id'],
            'name'            => $param['name'],
            'start_time'      => strtotime($param['start_time']),
            'end_time'        => strtotime($param['end_time']),
            'is_repeat'       => $param['is_repeat'],
            'lock_time'       => $param['lock_time']*60,
            'start_lock_time' => $param['start_lock_time']*60,
            'question_number' => $param['question_number'],
            'one_point'       => $param['one_point'],
        ];
        return $this->insertGetId($data);
    }
    
    /**
     * 编辑
     * @param type $param
     */
    public function edit_data($param) {
         $data = [
            'category'        => $param['category'],
            'category_id'     => $param['category_id'],
            'name'            => $param['name'],
            'start_time'      => strtotime($param['start_time']),
            'end_time'        => strtotime($param['end_time']),
            'is_repeat'       => $param['is_repeat'],
            'lock_time'       => $param['lock_time']*60,
            'start_lock_time' => $param['start_lock_time']*60,
            'question_number' => $param['question_number'],
            'one_point'       => $param['one_point'],
        ];
        return $this->where(['id'=>$param['id']])->update($data);
    }
    
    /**
     * 删除数据
     * @param int $id
     */
    public function delete_data($id) {
        return $this->destroy($id);
    }
}